//
//  WCNSettingItemController.m
//  WCN
//
//  Created by wsj2015 on 15/9/16.
//  Copyright (c) 2015年 ShanghaiCize Trade And Business Co., Ltd. All rights reserved.
//

#import "WCNSettingItemController.h"
#import "WCNDefaultCell.h"
#import "Macros.h"
#import "WCNMeSettingVC.h"
#import "WCNetworkAccessManager.h"
#import "WCCoreDataStore.h"
#import "AccountServiceEntity.h"
#import "WCDefaultManager.h"
#import "WCPopupLayerManager.h"
#import "WCNServiceConfigModel.h"

@interface WCNSettingItemController ()<UITableViewDataSource,UITableViewDelegate>
{
    
    NSMutableArray   *_serviceConfigsArr;
    

}
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation WCNSettingItemController



-(instancetype)init
{
    if (self =[super init]) {
        
        
        _serviceConfigsArr =[NSMutableArray array];
       

    }
    return self;

}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor =kAppBg;
    self.tableView.alwaysBounceHorizontal =NO;
    self.title =@"服务设置";

   
    
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
     [self getServiceConfig];
    
}
-(void)getServiceConfig
{
   MBProgressHUD *hd =[[WCPopupLayerManager shareMg] showSimple:self.view];
    
    Account *account =[[WCDefaultManager shareMg] account];
    NSString *url =[NSString stringWithFormat:@"%@%@",kServiceConifg_part,account.stringId];
    [[WCNetworkAccessManager sharedMg] GET:url parameters:nil   success:^(NSDictionary *responseObject) {
        [_serviceConfigsArr removeAllObjects];
        NSDictionary *dataDict =responseObject[@"data"];
        for (NSDictionary *dict in dataDict[@"configs"]) {
            WCNServiceConfigModel *model =[[WCNServiceConfigModel alloc] init];
            [model setValuesForKeysWithDictionary:dict];
            [_serviceConfigsArr addObject:model];
        }
        [self.tableView reloadData]
        ;
    } failure:^(NSString *msg) {
        
    } netError:^(id error) {
        
    } always:^{
        [hd hide:YES];
    }];
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return _serviceConfigsArr.count;

}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 64;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    WCNServiceConfigModel *model =_serviceConfigsArr[indexPath.row];
    WCNDefaultCell *cell =[WCNDefaultCell cellForTableView:tableView];

    cell.textLabel.text =model.serviceName;
    cell.textLabel.font =[UIFont systemFontOfSize:20];
    cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
    return cell;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        
        WCNServiceConfigModel *config =_serviceConfigsArr[indexPath.row];
        WCNMeSettingVC *vc =[[WCNMeSettingVC alloc]init];
        vc.title =config.serviceName;
        vc.config =config;
       
      [self.navigationController pushViewController:vc animated:YES];
    
}




@end
